package com.kadron.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.validator.NotNull;

import com.kadron.base.KBase;

@Entity
@Table(name = "k_item_color", uniqueConstraints = { @UniqueConstraint(columnNames = {
		"item_id", "color_id" }) })
public class ItemColor extends KBase implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7592122117399771560L;

	protected Item item;
	protected ItemTypeColor color;
	protected int ordinal;

	public ItemColor() {
		super();
	}

	public ItemColor(Item item, ItemTypeColor color, int ordinal) {
		super();
		this.item = item;
		this.color = color;
		this.ordinal = ordinal;
	}

	@NotNull
	@ManyToOne(targetEntity = Item.class)
	@JoinColumn(name = "item_id", nullable = false)
	public Item getItem() {
		return item;
	}

	public void setItem(Item item) {
		this.item = item;
	}

	@NotNull
	@ManyToOne(targetEntity = ItemTypeColor.class)
	@JoinColumn(name = "color_id", nullable = false)
	public ItemTypeColor getColor() {
		return color;
	}

	public void setColor(ItemTypeColor color) {
		this.color = color;
	}
	
	@Column(name = "ordinal", nullable = false)
	public int getOrdinal() {
		return ordinal;
	}

	public void setOrdinal(int ordinal) {
		this.ordinal = ordinal;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ItemColor other = (ItemColor) obj;
		if (id != other.id)
			return false;
		return true;
	}
	
	
}
